package com.msite.model.param;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by tpeng on 2016/4/1.
 */
public class BaseParam {

    // Grid 参数
    private Integer page = 1;
    private Integer pagesize = 10;
    private String sortname;
    private String sortorder;

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getPagesize() {
        return pagesize;
    }

    public void setPagesize(Integer pagesize) {
        this.pagesize = pagesize;
    }

    public String getSortname() {
        return sortname;
    }

    public void setSortname(String sortname) {
        this.sortname = sortname;
    }

    public String getSortorder() {
        return sortorder;
    }

    public void setSortorder(String sortorder) {
        this.sortorder = sortorder;
    }

    /**
     * 将request请求参数统一接收Map格式，并重新request.setAttribute 返回到页面
     * @author tpeng
     */
    @Deprecated
    public static Map<String,String> initParamMap(HttpServletRequest request){
        Map<String,String> rmap = new HashMap<String,String>();
        Map paramMap = request.getParameterMap();
        for (Object obj : paramMap.entrySet()) {
            Map.Entry entry = (Map.Entry)obj;
            String name = (String) entry.getKey();
            String value = "";
            Object valObj = entry.getValue();
            if(valObj != null){
                if(valObj instanceof String[]){
                    String[] values = (String[])valObj;
                    for(int i=0; i< values.length; i++){
                        value += values[i] + ",";
                    }
                    value = value.substring(0, value.length()-1);
                }else{
                    value = valObj.toString();
                }
                request.setAttribute(name, value);
                rmap.put(name, value);
            }
        }
        return rmap;
    }

}
